# 设置CMake的最小版本
cmake_minimum_required(VERSION 3.15)

# 项目名称
project(SearchEngine CXX)

# 指定C++的版本: -std=c++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置可执行程序生成的路径 (与您的风格保持一致，生成在项目根目录外)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ../)

# 目标 1: SearchEngine (主程序)
# 修改源文件路径
add_executable(SearchEngine
    src/SearchEngine/DirectoryScanner.cpp
    src/SearchEngine/KeywordProcessor.cpp
    src/SearchEngine/PageProcessor.cpp
    src/SearchEngine/TextUtils.cpp
    src/SearchEngine/XMLUtils.cpp
    src/SearchEngine/tinyxml2.cc
    src/SearchEngineServer/LogUtils.cpp
    src/SearchEngine/main.cpp
)

# 添加头文件包含目录
target_include_directories(SearchEngine PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/include/SearchEngine
    ${CMAKE_CURRENT_SOURCE_DIR}/include/SearchEngineServer
)

# 设置编译选项
target_compile_options(SearchEngine PRIVATE
    -g
    # 启用常用的编译警告
    $<$<OR:$<COMPILE_LANG_AND_ID:CXX,GNU>,$<COMPILE_LANG_AND_ID:CXX,Clang>>:-Wall -Wextra>
)

# 设置链接库
target_link_libraries(SearchEngine PRIVATE 
    pthread   # -lpthread
    log4cpp  # -llog4cpp
)

# 设置编译宏定义
target_compile_definitions(SearchEngine
    PRIVATE
        # $<$<CONFIG:Debug>:DEBUG>
)

# 目标 2: SearchEngineServer (服务器程序)
# 修改源文件路径
add_executable(SearchEngineServer
    src/SearchEngineServer/Acceptor.cpp
    src/SearchEngineServer/SearchEngineServer.cpp
    src/SearchEngineServer/EventLoop.cpp
    src/SearchEngineServer/InetAddress.cpp
    src/SearchEngineServer/Socket.cpp
    src/SearchEngineServer/SocketIO.cpp
    src/SearchEngineServer/TaskQueue.cpp
    src/SearchEngineServer/TcpConnection.cpp
    src/SearchEngineServer/TcpServer.cpp
    src/SearchEngineServer/ThreadPool.cpp
    src/SearchEngineServer/KeyRecommanderTask.cpp
    src/SearchEngineServer/WebPageSearcherTask.cpp
    src/SearchEngineServer/QueryEngine.cpp
    src/SearchEngine/TextUtils.cpp
    src/SearchEngine/XMLUtils.cpp
    src/SearchEngine/tinyxml2.cc
    src/SearchEngineServer/LogUtils.cpp
    src/SearchEngineServer/CacheUtils.cpp
    src/SearchEngineServer/main.cpp
)

# 添加头文件包含目录
target_include_directories(SearchEngineServer PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/include/SearchEngineServer
    ${CMAKE_CURRENT_SOURCE_DIR}/include/SearchEngine
)

# 设置编译选项
target_compile_options(SearchEngineServer PRIVATE
    -g
    # 启用常用的编译警告
    $<$<OR:$<COMPILE_LANG_AND_ID:CXX,GNU>,$<COMPILE_LANG_AND_ID:CXX,Clang>>:-Wall -Wextra>
)

# 设置链接库
target_link_libraries(SearchEngineServer PRIVATE 
    pthread  # -lpthread
    log4cpp  # -llog4cpp
    redis++  # -lredis++
    hiredis  # -lhiredis
)

# 设置编译宏定义
target_compile_definitions(SearchEngineServer
    PRIVATE
        # $<$<CONFIG:Debug>:DEBUG>
)

# 目标 3: SearchEngineClient (客户端程序)
# 修改源文件路径
add_executable(SearchEngineClient
    src/SearchEngineServer/ConsoleUtils.cpp
    src/SearchEngineServer/NetUtils.cpp
    src/SearchEngineServer/SearchEngineClient.cpp
)

# 添加头文件包含目录
target_include_directories(SearchEngineClient PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/include/SearchEngineServer
)

# 设置编译选项
target_compile_options(SearchEngineClient PRIVATE
    -g
    # 启用常用的编译警告
    $<$<OR:$<COMPILE_LANG_AND_ID:CXX,GNU>,$<COMPILE_LANG_AND_ID:CXX,Clang>>:-Wall -Wextra>
)

# 设置链接库
target_link_libraries(SearchEngineClient PRIVATE 

)

# 设置编译宏定义
target_compile_definitions(SearchEngineClient
    PRIVATE
        # $<$<CONFIG:Debug>:DEBUG>
)
